"use strict";
//定义一个类
class Polygon {
    //构造函数
    constructor(height, width) {
        this.height = height;
        this.width = width;
    };

    //定义的是getter
    get area() {
        return this.calcArea()
    };

    //定义的是方法
    calcArea() {
        return this.height * this.width;
    };

    //定义setter
    set prop1(val){
        this.prop11 = val;
    };
}

console.log("old p1");
var p1 = new Polygon(1, 2);
console.log(p1.area);
console.log(p1.calcArea());


//修改类的定义
// console.log(Polygon.prototype.area);
// 
(function () {
    var bak = Polygon.prototype.area;

    //重新定义area属性
    Object.defineProperty(Polygon.prototype, "area", {
        get: function () {
            console.log("changeed area!!");
            return bak;
        }
    });

    //直接定义的方法
    console.log(Polygon.prototype.calcArea);

    //先备份原来的定义
    var bak_cal = Polygon.prototype.calcArea;

    //设置为新的方法
    Polygon.prototype.calcArea = function () {
        console.log("changed calcArea!!");
        //绑定this
        return bak_cal.bind(this).apply();
    };
})();

// Polygon.prototype.area = function(){
//     console.log("changeed");
//     Polygon.area;
// }
console.log("new p1");
console.log(p1.area);
console.log(p1.calcArea());

console.log("new p2");
var p2 = new Polygon(12, 32);
console.log(p2.area);
console.log(p2.calcArea());


//修改setter
console.log("p2.prop1 is old!");
console.log(p2.prop1 = 100);
console.log(p2);
console.log(Object.getPrototypeOf(Polygon));
(function(){
    //重新定义area属性
    Object.defineProperty(Polygon.prototype, "prop1", {
        set: function (value) {
            console.log("changeed prop1!!");
            this.prop11 = value;
        }
    });
})();
console.log("p2.prop1 is new!");
console.log(p2.prop1 = 1);
console.log(p2);
console.log(Object.getPrototypeOf(Polygon));